package com.openbravo.pos.printer.escpos;

import com.openbravo.pos.printer.DeviceTicket;
import java.awt.image.BufferedImage;

public abstract class Codes
{
  public abstract byte[] getInitSequence();

  public abstract byte[] getSize0();

  public abstract byte[] getSize1();

  public abstract byte[] getSize2();

  public abstract byte[] getSize3();

  public abstract byte[] getBoldSet();

  public abstract byte[] getBoldReset();

  public abstract byte[] getUnderlineSet();

  public abstract byte[] getUnderlineReset();

  public abstract byte[] getOpenDrawer();

  public abstract byte[] getCutReceipt();

  public abstract byte[] getNewLine();

  public abstract byte[] getImageHeader();

  public abstract int getImageWidth();

  public void printBarcode(PrinterWritter paramPrinterWritter, String paramString1, String paramString2, String paramString3)
  {
    if ("EAN13".equals(paramString1))
    {
      paramPrinterWritter.write(getNewLine());
      paramPrinterWritter.write(ESCPOS.BAR_HEIGHT);
      if ("none".equals(paramString2))
        paramPrinterWritter.write(ESCPOS.BAR_POSITIONNONE);
      else
        paramPrinterWritter.write(ESCPOS.BAR_POSITIONDOWN);
      paramPrinterWritter.write(ESCPOS.BAR_HRIFONT1);
      paramPrinterWritter.write(ESCPOS.BAR_CODE02);
      paramPrinterWritter.write(DeviceTicket.transNumber(DeviceTicket.alignBarCode(paramString3, 13).substring(0, 12)));
      paramPrinterWritter.write(new byte[] { 0 });
      paramPrinterWritter.write(getNewLine());
    }
  }

  public byte[] transImage(BufferedImage paramBufferedImage)
  {
    CenteredImage localCenteredImage = new CenteredImage(paramBufferedImage, getImageWidth());
    int i = (localCenteredImage.getWidth() + 7) / 8;
    int j = localCenteredImage.getHeight();
    byte[] arrayOfByte = new byte[getImageHeader().length + 4 + i * j];
    System.arraycopy(getImageHeader(), 0, arrayOfByte, 0, getImageHeader().length);
    int k = getImageHeader().length;
    arrayOfByte[(k++)] = (byte)(i % 256);
    arrayOfByte[(k++)] = (byte)(i / 256);
    arrayOfByte[(k++)] = (byte)(j % 256);
    arrayOfByte[(k++)] = (byte)(j / 256);
    for (int n = 0; n < localCenteredImage.getHeight(); n++)
    {
      int i1 = 0;
      while (i1 < localCenteredImage.getWidth())
      {
        int m = 0;
        for (int i2 = 0; i2 < 8; i2++)
        {
          m <<= 1;
          if (!localCenteredImage.isBlack(i1 + i2, n))
            continue;
          m |= 1;
        }
        arrayOfByte[(k++)] = (byte)m;
        i1 += 8;
      }
    }
    return arrayOfByte;
  }

  protected class CenteredImage
  {
    private BufferedImage image;
    private int width;

    public CenteredImage(BufferedImage paramInt, int arg3)
    {
      this.image = paramInt;
      int i;
      this.width =arg3;
    }

    public int getHeight()
    {
      return this.image.getHeight();
    }

    public int getWidth()
    {
      return this.width;
    }

    public boolean isBlack(int paramInt1, int paramInt2)
    {
      int i = paramInt1 + (this.image.getWidth() - this.width) / 2;
      if ((i < 0) || (i >= this.image.getWidth()) || (paramInt2 < 0) || (paramInt2 >= this.image.getHeight()))
        return false;
      int j = this.image.getRGB(i, paramInt2);
      int k = (int)(0.3D * (j >> 16 & 0xFF) + 0.59D * (j >> 8 & 0xFF) + 0.11D * (j & 0xFF));
      return k < 128;
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.printer.escpos.Codes
 * JD-Core Version:    0.6.0
 */